﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _08_EF
{
    class BookConfig : IEntityTypeConfiguration<Book>
    {
        public void Configure(EntityTypeBuilder<Book> builder)
        {
            //throw new NotImplementedException();
            builder.ToTable("T_Books");
            builder.Property(b => b.Title).HasMaxLength(50).IsRequired();
            builder.Property(b=>b.AuthorName).HasMaxLength(50).IsRequired();
            builder.Ignore(b => b.Age1);
            builder.Ignore(b => b.Age2);
            builder.Property(b => b.Age3).HasColumnName("Age");
            builder.Property(b => b.AuthorName).HasColumnName("AuthorNames");
            builder.Property(b => b.Name2).HasColumnType("varchar(8)");
            // 唯一索引
            builder.HasIndex(b => b.Title).IsUnique();
            // 复合索引
            builder.HasIndex(b => new { b.AuthorName, b.Name2 });
        }
    }
}
